# 1.导入pymysql
import pymysql
# 2.创建链接对象
conn = pymysql.connect(user='root', password='root', database='advanced', charset='utf8')
# 3.获取游标对象
cursor = conn.cursor()
# 4.执行sql语句
try:
    sql = 'insert into student(stu_no, stu_name) values("itsrc-015", "大乔")'
    rows = cursor.execute(sql)
    print(rows)
except Exception as e:
    conn.rollback()
    print(e)
else:
    conn.commit()
# 5.提交或者回滚
# 6.7关闭

cursor.close()
conn.close()